package san.web.dictionary;

import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import san.entity.dictionary.Dictionary;
import san.service.dictionary.DictionaryService;

@Controller
@RequestMapping(value="/dictionary")
public class DictionaryController {
	
	@Autowired
	private DictionaryService dictionaryservice;
	
	@RequestMapping(method=RequestMethod.GET)
	public String getCreateForm(Model model) {
		model.addAttribute(new Dictionary());
		return "dictionary/createForm";
	}
	
	@RequestMapping(method=RequestMethod.POST)
	public String create(@Valid Dictionary dictionary, BindingResult result) {
		if (result.hasErrors()) {
			return "dictionary/createForm";
		}
		System.out.println(dictionary.getName()+dictionary.getDescription());
		return "redirect:/dictionary/" + dictionary.getId();
	}
}
